'use strict';

const db = uniCloud.database()
exports.main = async (event, context) => {
	let {accountNumber, password} = event;
	
	try {
		// 查询用户
		const user = await db.collection('users').where({
			accountNumber: accountNumber,
		    password: password // 未加密
		}).get()
			
		if (user.data.length === 0) {
			return {
			  code: 400,
			  message: '用户名或密码错误'
			}
		  }
		
		// 登录成功，返回用户信息 未处理密码
		return {
			code: 200,
			message: '登录成功',
			data: user.data[0]
		}
	} catch(e) {
		return e
	}

};
